package demo3.demo4;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.net.Socket;

@Component
public class Client implements InitializingBean, DisposableBean {
    private Socket socket;
    private String host;
    private int port;
    @Value("${Client.host}")
    public void setHost(String host){
        this.host = host;
    }
    @Value("${Client.port}")
    public void setPort(int port){
        this.port = port;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Socket socket = new Socket(host, port);
    }
    @Override
    public void destroy() throws Exception {
        if(socket!=null){
            socket.close();
        }
    }
}
